//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class List {
    static class ListNode{
        public int value;
        public ListNode next;
        public ListNode(int value){
            this.value = value;
        }
    }

    public ListNode head;
    public void createList() {

        ListNode node1 = new ListNode(12);
        ListNode node2 = new ListNode(23);
        ListNode node3 = new ListNode(34);
        ListNode node4 = new ListNode(45);
        ListNode node5 = new ListNode(56);

        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;

        this.head = node1;

    }

    public void size() {
        ListNode cur = head;
        int count = 0;
        while (cur.next != null){
            cur = cur.next;
            count++;
        }
        System.out.println(count);
    }
    //考虑第一个为key
    public void removeAllKet(int key){
        if (head == null){
            return;
        }
        ListNode prev = head;
        ListNode cur = head.next;

        while (cur != null){
            if (cur.value == key){
                prev.next = cur.next;
                cur = cur.next;
            }else {
                prev = cur;
                cur = cur.next;
            }
        }
        if (head.value == key){
            head = head.next;
        }
    }
    public void clear(){
        this.head = null;
    }
}